package com.example.boot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.LogAnno;
import com.example.common.Result;
import com.example.common.enums.LogType;
import com.example.pojo.entity.Stage;
import com.example.pojo.vo.StageVO;
import com.example.service.StageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @author ding
 * @since 2024/6/11
 */
@RestController
@RequestMapping("/stage")
@Slf4j
@Api(tags = "阶段相关接口")
public class StageController {

    @Autowired
    private StageService stageService;

    /**
     * 分页查询
     */
    @ApiOperation("分页获取阶段信息")
    @GetMapping("/selectPage")
    public Result selectPage(String projectName,
                             String order,
                             Integer projectId,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        Page<Stage> page = stageService.selectPage(projectName, order, projectId, pageNum, pageSize);
        return Result.success(page);
    }

    @LogAnno(title = "阶段管理", type = LogType.ADD)
    @PostMapping("/add")
    public Result add(@RequestBody Stage stage){
        stageService.addStage(stage);
        return Result.success();
    }

    @LogAnno(title = "阶段管理", type = LogType.UPDATE)
    @PutMapping("/update")
    public Result update(@RequestBody Stage stage){
        stageService.updateStage(stage);
        return Result.success();
    }

    @LogAnno(title = "阶段管理", type = LogType.DELETE)
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        stageService.deleteById(id);
        return Result.success();
    }

    @LogAnno(title = "阶段管理", type = LogType.DELBATCH)
    @DeleteMapping("/delete/batch")
    public Result delBatch(@RequestBody List<Integer> ids){
        stageService.delBatch(ids);
        return Result.success();
    }

    @GetMapping("/selectProjectId/{projectId}")
    public Result selectByProjectId(@PathVariable Integer projectId){
        StageVO stageVO = stageService.selectByProjectId(projectId);
        return Result.success(stageVO);
    }

}
